package com.wuren.faceSwiping.drafts.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wuren.faceSwiping.drafts.entity.AppDrafts;
import com.wuren.faceSwiping.drafts.mapper.DraftsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DraftsService extends ServiceImpl<DraftsMapper, AppDrafts> {

    @Autowired
    private DraftsMapper draftsMapper;

    /**
     * 添加草稿箱
     * @param appDrafts
     * @return
     */
    public int addDrafts(AppDrafts appDrafts){
        return draftsMapper.insert(appDrafts);
    }

    /**
     * 查询草稿箱
     * @return
     */
    public List findDrafts(int id ,int salesmanId){
        QueryWrapper q = new QueryWrapper();
        if (id!=0){
            q.eq("id",id);
        }
        if (salesmanId!=0){
            q.eq("salesmanId",salesmanId);
        }
        return draftsMapper.selectList(q);
    }

    /**
     * 根据id删除草稿箱
     * @param id 草稿箱id
     * @return
     */
    public int deleteDrafts(int id){
        return draftsMapper.deleteById(id);
    }

    /**
     * 根据id修改草稿箱
     * @param appDrafts
     * @return
     */
    public int updateDrafts(AppDrafts appDrafts){
        return draftsMapper.updateById(appDrafts);
    }


}
